//package com.example.thirdannotation.y2022.annotation.advise;
//
//import com.example.thirdannotation.y2022.annotation.utils.R;
//import org.springframework.validation.FieldError;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * @author: dangwen
// * @createDate: 2021/10/17
// */
//@RestControllerAdvice(basePackages = "com.example.thirdannotation.y2022.annotation.controller")
//public class GlobalControllerAdvice {
//    @ExceptionHandler(value = MethodArgumentNotValidException.class)
//    public R handleValidationException(MethodArgumentNotValidException e){
//        Map<String, String> errorMap = new HashMap<>();
//        List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
//        for (FieldError fieldError: fieldErrors) {
//            errorMap.put(fieldError.getField(),fieldError.getDefaultMessage());
//        }
//        return R.error(999, "999error").put("data",errorMap);
//    }
//
//    @ExceptionHandler(value = Throwable.class)
//    public R handleGlobalException(Throwable t){
//
////       return R.error(BizCodeEnum.UNKNOWN_EXCEPTION.getCode(),BizCodeEnum.UNKNOWN_EXCEPTION.getMsg());
//        return R.error().put("exception",t.getMessage());
//    }
//}
